home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / apport / packaging.py < prev    next >
Encoding:
Python Source  |  2009-04-06  |  6.6 KB  |  156 lines

  1. '''Class that abstracts and encapsulates all packaging system queries that the
  2. various parts of apport need.
  3.  
  4. Copyright (C) 2007 Canonical Ltd.
  5. Author: Martin Pitt <martin.pitt@ubuntu.com>
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
  11. the full text of the license.
  12. '''
  13.  
  14. class PackageInfo:
  15.     def get_version(self, package):
  16.         '''Return the installed version of a package.'''
  17.  
  18.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  19.  
  20.     def get_available_version(self, package):
  21.         '''Return the latest available version of a package.'''
  22.  
  23.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  24.  
  25.     def get_dependencies(self, package):
  26.         '''Return a list of packages a package depends on.'''
  27.  
  28.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  29.  
  30.     def get_source(self, package):
  31.         '''Return the source package name for a package.'''
  32.  
  33.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  34.  
  35.     def is_distro_package(self, package):
  36.         '''Check if a package is a genuine distro package (True) or comes from
  37.         a third-party source.'''
  38.  
  39.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  40.  
  41.     def get_architecture(self, package):
  42.         '''Return the architecture of a package.
  43.  
  44.         This might differ on multiarch architectures (e. g.  an i386 Firefox
  45.         package on a x86_64 system)'''
  46.  
  47.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  48.  
  49.     def get_files(self, package):
  50.         '''Return list of files shipped by a package.'''
  51.  
  52.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  53.  
  54.     def get_modified_files(self, package):
  55.         '''Return list of all modified files of a package.'''
  56.  
  57.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  58.  
  59.     def get_file_package(self, file, uninstalled=False, map_cachedir=None):
  60.         '''Return the package a file belongs to, or None if the file is not
  61.         shipped by any package.
  62.         
  63.         If uninstalled is True, this will also find files of uninstalled
  64.         packages; this is very expensive, though, and needs network access and
  65.         lots of CPU and I/O resources. In this case, map_cachedir can be set to
  66.         an existing directory which will be used to permanently store the
  67.         downloaded maps. If it is not set, a temporary directory will be used.'''
  68.  
  69.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  70.  
  71.     def get_system_architecture(self):
  72.         '''Return the architecture of the system, in the notation used by the
  73.         particular distribution.'''
  74.  
  75.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  76.  
  77.     def set_mirror(self, url):
  78.         '''Explicitly set a distribution mirror URL for operations that need to
  79.         fetch distribution files/packages from the network.
  80.  
  81.         By default, the mirror will be read from the system configuration
  82.         files.'''
  83.  
  84.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  85.  
  86.     def get_source_tree(self, srcpackage, dir, version=None):
  87.         '''Download given source package and unpack it into dir (which should
  88.         be empty).
  89.  
  90.         This also has to care about applying patches etc., so that dir will
  91.         eventually contain the actually compiled source.
  92.  
  93.         If version is given, this particular version will be retrieved.
  94.         Otherwise this will fetch the latest available version.
  95.  
  96.         Return the directory that contains the actual source root directory
  97.         (which might be a subdirectory of dir). Return None if the source is
  98.         not available.'''
  99.  
  100.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  101.  
  102.     def compare_versions(self, ver1, ver2):
  103.         '''Compare two package versions.
  104.  
  105.         Return -1 for ver < ver2, 0 for ver1 == ver2, and 1 for ver1 > ver2.'''
  106.  
  107.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  108.  
  109.     def enabled(self):
  110.         '''Return whether Apport should generate crash reports.
  111.  
  112.         Signal crashes are controlled by /proc/sys/kernel/core_pattern, but
  113.         some init script needs to set that value based on a configuration file.
  114.         This also determines whether Apport generates reports for Python,
  115.         package, or kernel crashes.
  116.         
  117.         Implementations should parse the configuration file which controls
  118.         Apport (such as /etc/default/apport in Debian/Ubuntu).
  119.         '''
  120.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  121.  
  122.     def get_kernel_package(self):
  123.         '''Return the actual Linux kernel package name.
  124.  
  125.         This is used when the user reports a bug against the "linux" package.
  126.         '''
  127.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  128.  
  129.     def install_retracing_packages(self, report, verbosity=0,
  130.             unpack_only=False, no_pkg=False, extra_packages=[]):
  131.         '''Install packages which are required to retrace a report.
  132.         
  133.         If package installation fails (e. g. because the user does not have root
  134.         privileges), the list of required packages is printed out instead.
  135.  
  136.         If unpack_only is True, packages are only temporarily unpacked and
  137.         purged again after retrace, instead of permanently and fully installed.
  138.         If no_pkg is True, the package manager is not used at all, but the
  139.         binary packages are just unpacked with low-level tools; this speeds up
  140.         operations in fakechroots, but makes it impossible to cleanly remove
  141.         the package, so only use that in apport-chroot.
  142.         
  143.         Return a tuple (list of installed packages, string with outdated packages).
  144.         '''
  145.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  146.  
  147.     def remove_packages(self, packages, verbosity=0):
  148.         '''Remove packages.
  149.  
  150.         This is called after install_retracing_packages() to clean up again
  151.         afterwards. packages is a list of package names.
  152.         '''
  153.         raise NotImplementedError, 'this method must be implemented by a concrete subclass'
  154.  
  155. import packaging_impl
  156.